<%@ page contentType="text/html; charset=utf-8" %>
<%@ include file="/WEB-INF/jsp/includeTaglib.jsp" %>
<table class="dbborder" width="100%" border="0" cellpadding="0" cellspacing="1">
	<tr class="rowHead">
		<td height="20" width="20" align="center"></td>
		<td height="20" nowrap align="center" class="globalTextBold">门店编号</td>
		<td height="20" nowrap align="center" class="globalTextBold">门店名称</td>
		<td height="20" nowrap align="center" class="globalTextBold">地址</td>
		<td height="20" nowrap align="center" class="globalTextBold">行政区域</td>
<!-- 		<td height="20" nowrap align="center" class="globalTextBold">促销员配额</td> -->
<!-- 		<td height="20" nowrap align="center" class="globalTextBold">促销员数量</td> -->
		<td height="20" nowrap align="center" class="globalTextBold">操作</td>
	</tr>
	<c:forEach var="projectStore" items="${page.data}" varStatus="status">
		<tr class="rowClass">
			<td height="20" width="20" align="center"></td>
			<td height="20" class="globalText">${projectStore.channel_code}</td>
			<td height="20" class="globalText">${projectStore.channel_name}</td>
			<td height="20" class="globalText">${projectStore.channel_address}</td>
			<td height="20" class="globalText">${projectStore.channel_province_ad_name}-${projectStore.channel_city_ad_name}-${projectStore.channel_ad_name}</td>
<%--             <td height="20" class="globalText">${projectStore.required_sales_number}</td> --%>
<%--             <td height="20" class="globalText">${projectStore.assigned_sales_number}</td> --%>
            <td height="20" class="globalText">
				<input type="button" storeId="${projectStore.id}" class="btnStyle operateBtn" value="配置" onclick="javascript:assignSales(this)">
			</td>
		</tr>
	</c:forEach>
</table>

<%@ include file="/WEB-INF/jsp/includePagination.jsp"%>




<script>
	var assignedIds=new Array();
	
	<c:forEach var="storeId" items="${assignedIds}" varStatus="status">
		assignedIds.push(${storeId});
	</c:forEach>

	
	function findId(id){
		for(var i=0;i<assignedIds.length;i++){
			if(assignedIds[i]==id){
				return id;
			}
		}
		return null;
	}
	
	function assignSales(obj){
		var action=$(obj).attr("action");
		var projSalesId=$("#saleId").val();
		var storeIds=$(obj).attr("storeId");
		var projectId=$("#projectId").val();
		
		$(obj).attr("disabled","disabled");
		$.getJSON("<c:url value="/project/salesPromoterSalesPromoterAssign.html" />?action="+action+"&projSalesId="+projSalesId+"&storeIds="+storeIds+"&projectId="+projectId, function(jsonData){
			
			if(jsonData.success){
				alert("门店操作成功");
				if(action=="bind"){
					$(obj).val("解除");
					$(obj).attr("action","unbind");
					$(obj).css("color","red");
				}else{
					$(obj).val("分配");
					$(obj).attr("action","bind");
					$(obj).css("color","green");
				}
			}else{
				alert("门店操作失败");
			}
			
			$(obj).attr("disabled","");
		});
	}
	
	$(".operateBtn").each(function(){
		
		if(findId($(this).attr("storeId"))!=null){
			$(this).val("解除");
			$(this).attr("action","unbind");
			$(this).css("color","red");
		}else{
			$(this).val("分配");
			$(this).attr("action","bind");
			$(this).css("color","green");
		}
	});
	
	
</script>







